import numpy as np
import plotly.graph_objects as go
# Generate the grid of x and y values
x = np.linspace(-2, 2, 200)
y = np.linspace(-2, 2, 200)
x, y = np.meshgrid(x, y)
# Define the circular mask
radius = 2
mask = x**2 + y**2 <= radius**2
# Define the hyperbolic paraboloid equation z = (x^2 / a^2) - (y^2 / b^2)
a = 1 # scale factor for x
b = 1 # scale factor for y
z = (x**2 / a**2) - (y**2 / b**2)
# Apply the mask to the z values
z[~mask] = np.nan # Set values outside the circle to NaN for visualization
# Create the 3D surface plot
fig = go.Figure(data=[go.Surface(z=z, x=x, y=y, colorscale='Viridis', showscale=False)])
# Add titles and labels
fig.update_layout(title='Hyperbolic Paraboloid (Pringle Chip Shape)',
scene=dict(
xaxis_title='X-axis',
yaxis_title='Y-axis',
zaxis_title='Z-axis',
aspectmode='manual',
aspectratio=dict(x=1, y=1, z=0.5)
))
# Show the plot
fig.show()Quadric Surfaces (continued)
Hyperbolic Paraboloid
The hyperbolic paraboloid
Alternative method:
# Source: https://dkmj.org/ipython/2415s16/xy-hyperboloid.html
import plotly.offline as py
from plotly.graph_objs import *
import numpy as np
from numpy import pi, cos, sin, exp, log, sqrt
py.init_notebook_mode()
def curve(rfun,tmin=-2,tmax=2,tpts=200,color='black'):
domain = np.linspace(tmin,tmax,tpts)
r = [[rfun(t)[i] for t in domain] for i in range(3)]
trace = Scatter3d(x=r[0],y=r[1],z=r[2],mode='lines',
line=Line(color=color,width=3))
return(trace)
def snake(u,v):
lu, lv = len(u), len(v)
path = []
i, j = 0, 0
istep, jstep = 1, 1
while(i < lu):
while(0 <= j < lv):
path.append((u[i],v[j]))
j += jstep
j -= jstep
i += istep
jstep *= -1
i -= istep
i -= istep
istep *= -1
while(0 <= j < lv):
while(0 <= i < lu):
path.append((u[i],v[j]))
i += istep
i -= istep
j += jstep
istep *= -1
return path
def surface(rfun,tmin=-2,tmax=2,tpts=20,umin=-2,umax=2,upts=20,color='black'):
t, u = np.linspace(tmin,tmax,tpts), np.linspace(umin,umax,upts)
path = snake(t,u)
r = [[rfun(t,u)[i] for (t,u) in path] for i in range(3)]
trace = Scatter3d(x=r[0],y=r[1],z=r[2],mode='lines',
line=Line(color=color,width=3))
return(trace)
f = lambda x,y: x*y
xmin=-1
xmax=1
ymin=-1
ymax=1
s = surface(lambda t,u: (t,u,f(t,u)),color='green',tmin=xmin,tmax=xmax,umin=ymin,umax=ymax) #surface z=f(x,y)
py.iplot(Figure(data=Data([s])))/home/fes33/Documents/Work_-_Web/Worldlines/env/lib/python3.9/site-packages/plotly/graph_objs/_deprecations.py:378: DeprecationWarning:
plotly.graph_objs.Line is deprecated.
Please replace it with one of the following more specific types
- plotly.graph_objs.scatter.Line
- plotly.graph_objs.layout.shape.Line
- etc.
/home/fes33/Documents/Work_-_Web/Worldlines/env/lib/python3.9/site-packages/plotly/graph_objs/_deprecations.py:31: DeprecationWarning:
plotly.graph_objs.Data is deprecated.
Please replace it with a list or tuple of instances of the following types
- plotly.graph_objs.Scatter
- plotly.graph_objs.Bar
- plotly.graph_objs.Area
- plotly.graph_objs.Histogram
- etc.